﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HouseHoldBudget.Framework.Mvc;
using HouseHoldBudget.Infrastructure;
using HouseHoldBudget.Models.Expenses;
using HouseHoldBudget.Models.Incomes;

namespace HouseHoldBudget.Models.User
{
    public class BudgetUserModel : MvcEntityModelBase
    {

        public BudgetUserModel()
        {
            UserId = new Guid();
            FixedIncomes = new List<FixedIncomeModel>();
            OccasionnalIncomes = new List<OccasionalIncomeModel>();
            Expenses = new List<ExpenseModel>();
        }

        public BudgetUserModel(Guid userId)
        {
            UserId = userId;
        }

        /// <summary>
        /// Gets or sets the user id.
        /// </summary>
        /// <value>
        /// The user id.
        /// </value>
        public Guid UserId { get; set; }

        /// <summary>
        /// Gets or sets the budget id.
        /// </summary>
        /// <value>
        /// The budget id.
        /// </value>
        public Guid BudgetId { get; set; }

        /// <summary>
        /// Gets or sets the name of the user.
        /// </summary>
        /// <value>
        /// The name of the user.
        /// </value>
        public string UserFirstName { get; set; }

        /// <summary>
        /// Gets or sets the last name of the user.
        /// </summary>
        /// <value>
        /// The last name of the user.
        /// </value>
        public string UserLastName { get; set; }

        /// <summary>
        /// Gets or sets the full name of the user.
        /// </summary>
        /// <value>
        /// The full name of the user.
        /// </value>
        [ResourceDisplayName("Common_Owner")]
        public string UserFullName
        {
            get
            {
                return string.Format("{0} {1}", UserFirstName, UserLastName);
            }
        }

        /// <summary>
        /// Gets or sets the fixedincomes.
        /// </summary>
        /// <value>
        /// The fixedincomes.
        /// </value>
        public IList<FixedIncomeModel> FixedIncomes { get; set; }

        /// <summary>
        /// Gets or sets the occasionnal incomes.
        /// </summary>
        /// <value>
        /// The occasionnal incomes.
        /// </value>
        public IList<OccasionalIncomeModel> OccasionnalIncomes { get; set; }

        /// <summary>
        /// Gets or sets the expenses.
        /// </summary>
        /// <value>
        /// The expenses.
        /// </value>
        public IList<ExpenseModel> Expenses { get; set; }

        /// <summary>
        /// Gets the total incomes amount.
        /// </summary>
        /// <value>
        /// The total incomes amount.
        /// </value>
        [AllowHtml]
        [DataType(DataType.Currency)]
        public decimal TotalFixedIncomesAmount
        {
            get
            {
                if (FixedIncomes != null)
                    return FixedIncomes.Sum(p => p.FixedIncomesAmount);
                return 0;
            }
        }

        /// <summary>
        /// Gets the total occasional incomes amount.
        /// </summary>
        /// <value>
        /// The total occasional incomes amount.
        /// </value>
        [AllowHtml]
        [DataType(DataType.Currency)]
        public decimal TotalOccasionalIncomesAmount
        {
            get
            {
                if (OccasionnalIncomes != null)
                    return OccasionnalIncomes.Sum(p => p.OccasionalIncomesAmount);
                return 0;
            }
        }

        /// <summary>
        /// Gets the total incomes amount.
        /// </summary>
        /// <value>
        /// The total incomes amount.
        /// </value>
        [AllowHtml]
        [DataType(DataType.Currency)]
        public decimal TotalIncomesAmount
        {
            get
            {
                return TotalFixedIncomesAmount + TotalOccasionalIncomesAmount;
            }
        }

        /// <summary>
        /// Gets the total incomes amount.
        /// </summary>
        /// <value>
        /// The total incomes amount.
        /// </value>
        [AllowHtml]
        [DataType(DataType.Currency)]
        public decimal TotalExpenseAmount
        {
            get
            {
                return Expenses.Sum(s => s.ExpenseAmount);
            }
        }


    }
}